/**
 * @(#)MemoryUtils.java, 2015年3月28日. 
 * 
 * Copyright 2015 Youdao, Inc. All rights reserved.
 * YOUDAO PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package jadis.utils;

import com.google.common.base.Preconditions;

/**
 * @author yuanwq
 */
public class MemoryUtils {
    public static void memCopy(char[] to, char[] from) {
        memCopy(to, from, 0, from.length);
    }

    public static void memCopy(char[] to, char[] from, int start, int end) {
        Preconditions.checkArgument(end >= start);
        Preconditions.checkArgument(to.length >= end - start);
        for (int i = 0; i < end - start; i++) {
            to[i] = from[start + i];
        }
    }

    public static <T> void memCopy(T[] to, T[] from) {
        memCopy(to, from, 0, from.length);
    }

    public static <T> void memCopy(T[] to, T[] from, int start, int end) {
        Preconditions.checkArgument(end >= start);
        Preconditions.checkArgument(to.length >= end - start);
        for (int i = 0; i < end - start; i++) {
            to[i] = from[start + i];
        }
    }
}
